#!/bin/bash

now=`date '+%Y-%m-%d %H:%M:%S'` # 定义log的时间格式
grepFlag='xhs_main_111111.py' #
thisLog='./watchlog' # 该脚本的log日志文件
baseDir="."


# 无限循环（0<1）
now=`date '+%Y-%m-%d %H:%M:%S'`
ret=`ps aux | grep "$grepFlag" | grep -v grep | wc -l`
if [ $ret -eq 0 ]; then # 如果ps找不到运行的目标进程就拉起
    echo "$now process not exists ,restart process now... " >> "$thisLog"

    cd /home/lighthouse/xhs

    python3.10 $grepFlag & >> "$thisLog"

    echo "$now restart done ..... "  >> "$thisLog"
else
    echo "$now process exists , sleep $sleepTime seconds " >> "$thisLog"
    break
fi

sleep 2


ret=`ps aux | grep "$grepFlag" | grep -v grep | wc -l`
if [ $ret -eq 0 ]; then # 如果ps找不到运行的目标进程就拉起
    echo "$now process not exists ,restart process now... " >> "$thisLog"

    cd /home/ubuntu/xhs/
    python3.10 $grepFlag  >> "$thisLog"
    echo "$now restart done ..... "  >> "$thisLog"
else
    echo "$now process exists , sleep $sleepTime seconds " >> "$thisLog"
    break
fi
